home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.anim;
- import java.awt.Point;
-
- /**
- * This class implements a trajectory along a line, but with cartoonish
- * anticipation and overshoot. The first 20% of the line (0.0-0.2) are
- * spent in anticipation. We compute 10% of the distance traveled
- * (the dimensions x and y are dealt with separately) and move opposite
- * the target direction that amount and then back to our starting point.
- * This is done via a sin curve, so we are sure we end up where we started.
- * As we go across this line we are adding 5% of the total distance
- * traveled into the value and modulating that 5% with a sin function
- * so the object travels in a slightly curved path. The last 20% is
- * the overshoot, and we do that again with a sin.<p>
- *
- * @author Ian Smith
- */
- public class anticipation_line extends line_trajectory {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the amount of backup on anticipation. Defaults to 10%.
- */
- public static double antic_amount=0.1; /* 10% backup on anticipate */
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is amount of curvature to put in the path. Defaults to 5%.
- */
- public static double curve_amount=0.05; /* 5% extra curvature */
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the amount of overshoot at the end. Defaults to 10%.
- */
- public static double overshoot_amount=0.1; /* 10% overshoot */
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Where we start the anticipation and overshoot (in terms of time).
- * Defaults to 0.2.
- */
- public static double cutoff_point=0.2;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a cartoon line between two points.<P>
- *
- * You should make sure that if you use a pacing function which is
- * a slow_in_slow_out that the result of the slow part is 0.2
- * (== cutoff_point). <p>
- *
- * @param int x1 starting x coordinate
- * @param int y1 starting y coordinate
- * @param int x2 ending x coordinate
- * @param int y2 ending y coordinate
- */
- public anticipation_line(int x1, int y1, int x2, int y2, pacer p) {
- super(x1,y1,x2,y2,p);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This does the work for this trajectory. It maps the current time
- * onto a Point.<p>
- *
- * @param double parm the amount of time to be mapped
- */
- public Object object_for_parm(double parm) {
- double parameter=_pacer.pace(parm);
- double amountOfSine,sineval,dist_amount;
- int intsignx,intsigny;
- int newx, newy;
- int our_delta_x, our_delta_y;
-
- /* set the sign variables up */
- intsignx = _delta_x < 0 ? -1 : 1;
- intsigny = _delta_y < 0 ? -1 : 1;
-
- /* we want to make sure that we get some curvature even on
- lines which have same starting and end points equal in some dimension */
- if (Math.abs(_delta_x)<100) {
- our_delta_x=100*intsignx;
- } else {
- our_delta_x=_delta_x;
- }
-
- if (Math.abs(_delta_y)<100) {
- our_delta_y=100*intsigny;
- } else {
- our_delta_y=_delta_y;
- }
-
- /* are we in the first .2? */
- if (parameter<cutoff_point) {
-
- /* how much sine?*/
- amountOfSine=parameter/0.2;
- sineval=Math.sin(amountOfSine*Math.PI);
-
- /* compute new points */
- newx=_x_origin-(int)(sineval * (((double)our_delta_x)*(antic_amount)));
- newy=_y_origin-(int)(sineval * (((double)our_delta_x)*(antic_amount)));
- return new Point(newx, newy);
- }
-
- if (parameter<(1-cutoff_point)) {
-
- parameter-=0.2;
- dist_amount=parameter/0.6;
-
- /* how much sine?*/
- amountOfSine=parameter/0.6;
- sineval=Math.sin(amountOfSine*Math.PI);
-
- /* compute new points */
- newx=_x_origin+(int)(sineval * (((double)our_delta_x)*curve_amount));
- newy=_y_origin+(int)(sineval * (((double)our_delta_y)*curve_amount));
-
- /* at this point we have only added the curvature, add the distance
- traveled part now */
- /* these need to be the real delta_x and y because this is the
- * actual traversal part */
- newx+=(int)(dist_amount * (double)_delta_x);
- newy+=(int)(dist_amount * (double)_delta_y);
- return new Point(newx,newy);
- }
-
- /* final case: overshoot */
- parameter-=0.8;
- amountOfSine=parameter/0.2;
- sineval=Math.sin(amountOfSine*Math.PI);
-
- /* compute new points */
- newx=_x_origin+_delta_x+ /* this is real: amount traveled */
- (int)(sineval * (((double)our_delta_x)*(overshoot_amount)));
- newy=_y_origin+_delta_y+/* this is real: amount traveled */
- (int)(sineval * (((double)our_delta_y)*(overshoot_amount)));
-
- return new Point(newx, newy);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-